package com.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.yizisu.music.and.roomdblibrary.bean.SongWithSinger;

import com.yizisu.music.and.roomdblibrary.bean.SingerInfoTable;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "singer_info".
*/
public class SingerInfoTableDao extends AbstractDao<SingerInfoTable, Long> {

    public static final String TABLENAME = "singer_info";

    /**
     * Properties of entity SingerInfoTable.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property DbId = new Property(0, Long.class, "dbId", true, "_id");
        public final static Property Id = new Property(1, String.class, "id", false, "ID");
        public final static Property Source = new Property(2, Integer.class, "source", false, "SOURCE");
        public final static Property Type = new Property(3, Integer.class, "type", false, "TYPE");
        public final static Property Name = new Property(4, String.class, "name", false, "NAME");
        public final static Property Des = new Property(5, String.class, "des", false, "DES");
        public final static Property CreateTime = new Property(6, Long.class, "createTime", false, "CREATE_TIME");
        public final static Property UpdateTime = new Property(7, Long.class, "updateTime", false, "UPDATE_TIME");
    }

    private DaoSession daoSession;

    private Query<SingerInfoTable> songInfoTable_SingerInfoTablesQuery;

    public SingerInfoTableDao(DaoConfig config) {
        super(config);
    }
    
    public SingerInfoTableDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"singer_info\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: dbId
                "\"ID\" TEXT," + // 1: id
                "\"SOURCE\" INTEGER," + // 2: source
                "\"TYPE\" INTEGER," + // 3: type
                "\"NAME\" TEXT," + // 4: name
                "\"DES\" TEXT," + // 5: des
                "\"CREATE_TIME\" INTEGER," + // 6: createTime
                "\"UPDATE_TIME\" INTEGER);"); // 7: updateTime
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_singer_info_ID ON \"singer_info\"" +
                " (\"ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"singer_info\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, SingerInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(6, des);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(7, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(8, updateTime);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, SingerInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(5, name);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(6, des);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(7, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(8, updateTime);
        }
    }

    @Override
    protected final void attachEntity(SingerInfoTable entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public SingerInfoTable readEntity(Cursor cursor, int offset) {
        SingerInfoTable entity = new SingerInfoTable( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // dbId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // source
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // type
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // name
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // des
            cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6), // createTime
            cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7) // updateTime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, SingerInfoTable entity, int offset) {
        entity.setDbId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setSource(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setType(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setName(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setDes(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setCreateTime(cursor.isNull(offset + 6) ? null : cursor.getLong(offset + 6));
        entity.setUpdateTime(cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(SingerInfoTable entity, long rowId) {
        entity.setDbId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(SingerInfoTable entity) {
        if(entity != null) {
            return entity.getDbId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(SingerInfoTable entity) {
        return entity.getDbId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "singerInfoTables" to-many relationship of SongInfoTable. */
    public List<SingerInfoTable> _querySongInfoTable_SingerInfoTables(Long songId) {
        synchronized (this) {
            if (songInfoTable_SingerInfoTablesQuery == null) {
                QueryBuilder<SingerInfoTable> queryBuilder = queryBuilder();
                queryBuilder.join(SongWithSinger.class, SongWithSingerDao.Properties.SingerId)
                    .where(SongWithSingerDao.Properties.SongId.eq(songId));
                songInfoTable_SingerInfoTablesQuery = queryBuilder.build();
            }
        }
        Query<SingerInfoTable> query = songInfoTable_SingerInfoTablesQuery.forCurrentThread();
        query.setParameter(0, songId);
        return query.list();
    }

}
